package com.BlackMesa.controllers;

import java.awt.TextField;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.BlackMesa.models.OurLocation;
import com.BlackMesa.models.Task;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class SelectMapActive extends MapActivity {
	private MapView mapView;
	private MapViewController mvc;
	private MapController mc;
    private Task t;
    private Button yesBut, noBut;
    private EditText locText;
    
    
    class MapOverlay extends com.google.android.maps.Overlay
    {
    	private MapActivity activity;
    	private GeoPoint p;
    	private Dialog d;
    	
    	public MapOverlay(MapActivity activity){
    		this.activity = activity;
    	}
    	
    	
    	public boolean onTap(GeoPoint p,MapView mapView){
    		this.p = p;
    		alertBox("Select", "Is this the point you want?");
    		return true;
    	}
    	public void alertBox(String title, String mymessage) {
    		
    		/*
    		Dialog dialog = new Dialog(activity);
    		dialog.setContentView(R.layout.location_name);
    		dialog.setTitle("Name of this Location");
    		dialog.show();
    		d = dialog;
    		yesBut = (Button) dialog.findViewById(R.id.yesButton);
    		yesBut.setOnClickListener(new ClickList());
    		noBut = (Button) dialog.findViewById(R.id.noButton);
    		noBut.setOnClickListener(new ClickList());
    		locText = (EditText) dialog.findViewById(R.id.locationField);
    		 */
    		
    		new AlertDialog.Builder(this.activity)
    				.setMessage(mymessage)
    				.setTitle(title)
    				.setCancelable(false)
    				.setPositiveButton("Yes",
    						new DialogInterface.OnClickListener() {
    							public void onClick(DialogInterface dialog,
    									int whichButton) {
    								OurLocation t = new OurLocation("",p);
    								locationSender.setNewLast(p);
    								locationSender.add(t);
    								onBackPressed();
    							}
    						})
    				.setNegativeButton("No",
    						new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
								}		
							}).show();
    	}
    	private class ClickList implements OnClickListener{

    		public void onClick(View v) {
    			if(v.equals(yesBut)){
    				locationSender.add(new OurLocation(locText.getText().toString(),p));
    			}
				d.dismiss();
    		}
        	
        }
    } 
    
	
	/**
	 * method for route being displayed
	 * 
	 * @return
	 */
	protected boolean isRouteDisplayed() {
	    return false;
	}
	
	/**
	 * sets the view to map view and enables zoom
	 * 
	 * @param savedInstanceState
	 */
	public void onCreate(Bundle savedInstanceState) {  	
        super.onCreate(savedInstanceState);
	    setContentView(R.layout.map_view);
	    mapView = (MapView) findViewById(R.id.googlemapview);
	    mapView.setBuiltInZoomControls(true);
        MapOverlay mapOverlay = new MapOverlay(this);
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);        
 
        mapView.invalidate();
	}
	

    
}
